home *** CD-ROM | disk | FTP | other *** search
- Path: news.accessone.com!news
- From: bokr@accessone.com (Bengt Richter)
- Newsgroups: comp.lang.c++,comp.lang.pascal.delphi.misc
- Subject: Re: C++ with Zapp vs. Delphi
- Date: Wed, 24 Jan 1996 05:56:02 GMT
- Organization: -
- Message-ID: <4e4hrl$oqc@news.accessone.com>
- References: <4coar6$d4n@sun4.bham.ac.uk> <4coip7$69s@news1.usa.pipeline.com> <DBk8wg2yqjbB083yn@iaccess.za> <4d7pmb$48c8@tigger.cc.uic.edu> <4dk38h$gdr@merlin.delphi.com> <4dksp1$3d6c@tigger.cc.uic.edu> <30fe666e.3349285@130.15.126.54> <4durk2$2r54@tigger.cc.uic.edu> <31038877.2364473@130.15.126.54>
- NNTP-Posting-Host: bokr.accessone.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- dmurdoch@mast.queensu.ca (Duncan Murdoch) wrote:
-
- >olczyk@sunphy1 (Constantin Rasinariu) wrote:
-
- >>Duncan Murdoch (dmurdoch@mast.queensu.ca) wrote:
-
- [...]
- > What I want
- >is to have two lists (say AlphaList and NumericList) and put
- >references to the same object in both lists. The first would end up
- >sorted alphabetically, the second numerically.
-
- >Duncan
-
- PMJI from left field, but TStringlist has a Quicksort method which
- seems like it could be extracted and re-adapted to accept an external
- compare function (like C examples I've seen). It already operates with
- the array of object references in a TList, so it wouldn't seem like
- too big a deal to do just what you say. E.g., create one TList each
- for the AlphaList and NumericList, and put references to the same
- objects in both, then use the same quicksort on both, but passing
- alpha and numeric comparison functions respectively. Only the
- comparison functions need to know what kind of objects they are
- operating on. (Let unspecialized lists stick to knowing about their
- own structure). TList has an exchange method that can do the requisite
- swapping, (which is appropriate since it doesn't have to know what
- objects are being referred to).
- So you ought to be able to have a simple
- QuickSort(ATList,AComparisonFcn);
- call to do the job, where AComparisonFcn , might point to
-
- AlphaCompareTxx(const Left:TObject; const Right:TObject):integer;
- begin
- Result:=AnsiCompareText(Txx(Left).MyString,Txx(Right).MyString);
- end;
- or
- NumericCompareTxx(const Left:TObject; const Right:TObject):integer;
- begin
- Result:= Txx(Left).MyInteger-Txx(Right).MyInteger;
- end;
-
- You could use (Left as Txx).My... to check type validity, at some
- speed cost. Or you could use the type info iself to make those items
- go to the beginning or end of the list, etc.
-
- My 2 cents' worth. (Untested).
- Regards, Bengt Richter
-
-
-